package com.shop.service.impl;

import com.shop.bean.User;
import com.shop.dao.UserDao;
import com.shop.service.IShoppingLoginService;
import com.shop.service.IShoppingRegisterService;
import com.shop.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShoppingRegisterService implements IShoppingRegisterService {

    @Autowired
    UserDao userDao;
    @Override
    public User doregister(User user) {
        User user_data=userDao.getUserByUsername(user.getUsername());
        if(user_data != null){
            throw new RuntimeException("账号已存在！");
        }
        String hexpass= SYS.digest(user.getPassword());
        user.setPassword(hexpass);
        user.setImgurl("shopfile/img/icon/uploadimg.png");
        userDao.userRegister(user);
        user_data = userDao.getUserByUsername(user.getUsername());
        return user_data;
    }
}
